package com.bjpowernode.service.impl;

import com.bjpowernode.mapper.AdminMapper;
import com.bjpowernode.pojo.Admin;
import com.bjpowernode.pojo.AdminExample;
import com.bjpowernode.service.AdminService;
import com.bjpowernode.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//交给spring容器创建对象
@Service
public class AdminServiceImpl implements AdminService{
    //业务逻辑层一定有数据访问层对象
    @Autowired
    AdminMapper adminMapper;


    @Override
    public Admin login(String name, String pwd) {
//        根据传入用户到DB查询相应用户对象
//如果有条件则创建AdminExample对象，用来封装条件
        AdminExample example = new AdminExample();
        //添加同户名a_name条件
        example.createCriteria().andANameEqualTo(name);

        List<Admin> list = adminMapper.selectByExample(example);
        if (list.size()>0){
            Admin admin =list.get(0);
            //如果查到再进行密码比对密码是秘闻(前提加密了)
            if (pwd.equals(admin.getaPass())){
                return admin;
            }
        }

        return null;
    }
}
